// columns.ts
import DictTag, { DictValueEnum } from "@/components/DictTag";
import { ProColumns } from "@ant-design/pro-table";
import { Space, Typography } from "antd";

// 定义所有列的工厂函数
export const createTableColumns = (
	businessTypeOptions: DictValueEnum,
	operatorTypeOptions: DictValueEnum,
	handleColumnDetails: (record: API.Setting.OperlogVo) => void,
	handleColumnLog: (record: API.Setting.OperlogVo) => void
): ProColumns<API.Setting.OperlogVo>[] => {
	return [
		{
			title: "操作模块",
			dataIndex: "title",
			valueType: "text"
		},
		{
			title: "业务类型",
			dataIndex: "businessType",
			valueType: "select",
			valueEnum: businessTypeOptions,
			render: (_, record) => {
				return <DictTag enums={businessTypeOptions} value={String(record?.businessType)} />;
			}
		},
		{
			title: "请求方式",
			dataIndex: "requestMethod",
			valueType: "text"
		},
		{
			title: "操作类别",
			dataIndex: "operatorType",
			valueType: "select",
			valueEnum: operatorTypeOptions,
			render: (_, record) => {
				return <DictTag enums={operatorTypeOptions} type="tag" value={String(record?.operatorType)} />;
			}
		},
		{
			title: "耗时",
			dataIndex: "costTime",
			render: (_, record) => {
				return <>{record.costTime}毫秒</>;
			}
		},
		{
			title: "主机地址",
			dataIndex: "operIp",
			valueType: "text"
		},
		{
			title: "操作地点",
			dataIndex: "operLocation",
			valueType: "text"
		},
		{
			title: "操作人员",
			dataIndex: "operName",
			valueType: "text"
		},
		{
			title: "操作",
			dataIndex: "option",
			valueType: "option",
			render: (_, record: any) => {
				return (
					<Space>
						<Typography.Link
							key="details"
							onClick={() => {
								handleColumnDetails(record);
							}}
						>
							详情
						</Typography.Link>
						{record?.status === 1 && (
							<Typography.Link
								key="log"
								onClick={() => {
									handleColumnLog(record);
								}}
							>
								日志
							</Typography.Link>
						)}
					</Space>
				);
			}
		}
	];
};
export const tableTab: any = [
	{
		key: "oper",
		label: <span>操作日志</span>
	},
	{
		key: "error",
		label: <span>异常日志</span>
	}
];

export const tableStyle = {
	minHeight: "calc(100vh - 420px)"
};
export const pagination = {
	defaultPageSize: 10,
	showQuickJumper: true,
	showSizeChanger: true
};
